Dropdown List Handling

Multiple Dropdown Fields that Dynamically Update Each Other

Description
This customization shows how to implement multiple Dropdown list fields that dynamically update each other.
Variables
First Dropdown List Control
Select a dropdown list control whose items are populated from a number or character type field in the database
Second Dropdown List Control
Select another dropdown list control whose items are populated from a number or character type field in the database
Parent Record Control
Select the parent record control where the dropdown lists exist.
Table
Select the database table associated with the Parent Record Control
First Dropdown Field
Select the field associated with first dropdown list
Second Dropdown Field
Select the field associated with second dropdown list
Applies to
RecordControl class
Code
 
''' 
''' This method sets the AutoPostBack property of the field that triggers a change.
''' 
Protected Sub MultipleDropdown_myInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init

        ' AutoPostBack sets or retrieves a value that indicates whether or not the control
        ' posts back to the server each time a user interacts with the control. 
        ' if change in second drop down list updates the first then set
        ' AutoPostback of the second dropdown list to true and implement 
        ${First Dropdown List Control}.AutoPostBack = True
        ${Second Dropdown List Control}.AutoPostBack = True
        
        
    AddHandler ${First Dropdown List Control}.SelectedIndexChanged, AddressOf ${First Dropdown List Control}_SelectedIndexChanged
    ${Second Dropdown List Control}.Enabled = False

End Sub


  
 
Applies to
RecordControl class
Code
 
''' 
''' This method handles the SelectedIndexChanged for ${First Dropdown List Control} 
''' 
Protected Overrides Sub ${First Dropdown List Control}_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    ${Second Dropdown List Control}.Enabled = True

    ' ${Second Dropdown List Control} DropDownList will display 100 items.
    ' You can set the number of items displayed in the DropDownList.
    Me.Populate${Second Dropdown List Control}DropDown(100)
            
End Sub  
 
Applies to
RecordControl class
Code
 
''' 
''' Override this method to filter the  ${Second Dropdown List Control}DropDownList
''' based on the value selected for the ${First Dropdown List Control}DropDownList
''' 
Protected Sub Populate${Second Dropdown List Control}DropDown(ByVal maxItems As Integer)

    ' Set up the WHERE clause.
    ' Create the WHERE clause to filter the second dropdown list based on
    ' the selected value of first dropdown list.
    Dim wc As WhereClause = New WhereClause
    Dim selectedValue As String = ${First Dropdown List Control}.SelectedValue  
    Dim selectedText As String = ${First Dropdown List Control}.SelectedItem.Text
    wc.iAND(${${Table}ClassName}.${First Dropdown Field}, BaseFilter.ComparisonOperator.EqualsTo, selectedValue)

    ' Clear the contents of second dropdown list.
    Me.${Second Dropdown List Control}.Items.Clear()
    
    ' Add "Please Select" string to the second dropdown list.
    Me.${Second Dropdown List Control}.Items.Insert(0, New ListItem(Page.GetResourceValue("Txt:PleaseSelect", "${Application Name}"), "--PLEASE_SELECT--"))                      
    
    If (BaseClasses.Utils.StringUtils.InvariantUCase(selectedText).Equals(BaseClasses.Utils.StringUtils.InvariantUCase(Page.GetResourceValue("Txt:PleaseSelect", "${Application Name}"))))
        ' if "Please Select" string is selected for first dropdown list,
        ' then do not continue populating the second dropdown list.
        Return    
    End If
    
    ' Get the records using the created where clause.    
    Dim itemValue As ${${Table}RecordClassName}
    For Each itemValue In ${${Table}ClassName}.GetRecords(wc, Nothing, 0, maxItems)
            
        If (itemValue.${Second Dropdown Field}Specified)
            ' In each record, obtain the value of second dropdown field if value exists,
            ' create an item for it and add it to the list.
            Dim cvalue As String = itemValue.${Second Dropdown Field}.ToString()
            Dim fvalue As String = itemValue.Format(${${Table}ClassName}.${Second Dropdown Field})
            Dim item As ListItem = New ListItem(fvalue, cvalue)
            If (Not Me.${Second Dropdown List Control}.Items.Contains(item))
                Me.${Second Dropdown List Control}.Items.Add(item)        
            End If      
        End If
    Next                    

    ' Select "Please Select" string in the second dropdown list.
    Me.${Second Dropdown List Control}.SelectedIndex = 0
End Sub   
 

Terms of Service Privacy Statement